package com.shelpe.services.sinbad.controller.actionLog;

import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.entity.jpa.AdgroupLog;
import com.shelpe.services.sinbad.entity.jpa.CampaignLog;
import com.shelpe.services.sinbad.entity.jpa.CreativeLog;
import com.shelpe.services.sinbad.entity.jpa.KeywordsLog;

import lombok.Data;

@Data
@JsonInclude(Include.NON_DEFAULT)
public class ActionLogDto {
	@JsonProperty("log_id")
	private long logID;
	@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Shanghai")
	@JsonProperty("action_time")
	private Date actionTime;
	private String reason;
	private String action;

	@JsonProperty("action_type")
	private String actionType;// 操作动作：手动/自动 manual/auto
	private String type;// 操作记录类型：ps:campaign,adgroup,creative...
	private String name;
	@JsonProperty("adgroup_id")
	private long adgroupID;
	@JsonProperty("campaign_id")
	private long campaignID;
	@JsonProperty("creative_id")
	private long creativeID;
	@JsonProperty("keywrod_id")
	private long keywrodID;

	public void from(AdgroupLog entity) {
		this.actionTime = entity.getUpdatedTime();
		if (entity.getAction().toDisplay().contains("auto")) {
			this.action = "auto";
		} else {
			this.action = "manual";
		}
		this.logID = entity.getLogID();
	}

	public void from(CreativeLog entity) {
		this.actionTime = entity.getUpdatedTime();
		if (entity.getAction().toDisplay().contains("auto")) {
			this.action = "auto";
		} else {
			this.action = "manual";
		}
		this.logID = entity.getLogID();
	}

	public void from(KeywordsLog entity) {
		this.actionTime = entity.getUpdatedTime();
		if (entity.getAction().toDisplay().contains("auto")) {
			this.action = "auto";
		} else {
			this.action = "manual";
		}
		this.logID = entity.getLogID();
	}

	public void from(CampaignLog entity) {
		this.actionTime = entity.getUpdatedTime();
		this.action = "manual";
		if (entity.getAction().toDisplay().contains("auto")) {
			this.action = "auto";
		} 
		if (entity.getAction().toDisplay().contains("semiauto")) {
			this.action = "semiauto";
		}
		this.logID = entity.getLogID();
	}
}
